package com.jin;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.jin.domain.CheckItem;
import com.jin.domain.ChooseItem;
import com.jin.domain.FillItem;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;

public class ItemSource {

	public static List<CheckItem> checkItems;

	public static List<ChooseItem> chooseItems;

	public static List<FillItem> fillItems;
	
	static {
		init();
	}

	public static void init() {
		ClassLoader classLoader = ItemSource.class.getClassLoader();
		URL url = classLoader.getResource("panduan.xlsx");
		checkItems = new ArrayList<CheckItem>();
		File file = new File(url.getFile());
		ExcelReader reader = ExcelUtil.getReader(file);
		List<List<Object>> readAll = reader.read();
		for (int i = 0; i < readAll.size(); i++) {
			if (i == 0) {
				continue;
			}
			List<Object> listItem = readAll.get(i);
			String itemTitle = listItem.get(0).toString();
			String ansWer = listItem.get(1).toString();
			CheckItem checkItem = new CheckItem();
			checkItem.setItemTitle(itemTitle);
			checkItem.setAnswer("对".equals(ansWer) ? true : false);
			checkItem.setId(UUID.randomUUID().toString());
			checkItems.add(checkItem);
		}
		url = classLoader.getResource("tiankong.xlsx");
		fillItems = new ArrayList<FillItem>();
		file = new File(url.getFile());
		reader = ExcelUtil.getReader(file);
		readAll = reader.read();
		for (int i = 0; i < readAll.size(); i++) {
			if (i == 0) {
				continue;
			}
			List<Object> itemStr = readAll.get(i);
			FillItem fillItem = new FillItem();
			fillItem.setItemTitle(itemStr.get(0).toString());
			String[] ansWer = new String[itemStr.size() - 1];
			for (int j = 1; j < itemStr.size(); j++) {
				ansWer[j - 1] = itemStr.get(j).toString();
			}
			fillItem.setAnswers(ansWer);
			fillItem.setId(UUID.randomUUID().toString());
			fillItems.add(fillItem);
		}

		url = classLoader.getResource("xuanze.xlsx");
		chooseItems = new ArrayList<ChooseItem>();
		file = new File(url.getFile());
		reader = ExcelUtil.getReader(file);
		readAll = reader.read();
		for (int i = 0; i < readAll.size(); i++) {
			if (i == 0) {
				continue;
			}
			List<Object> itemStr = readAll.get(i);
			System.out.println(itemStr);
			ChooseItem chooseItem = new ChooseItem();
			chooseItem.setItemTitle(itemStr.get(0).toString());
			chooseItem.setChooseA(itemStr.get(1).toString());
			chooseItem.setChooseB(itemStr.get(2).toString());
			chooseItem.setChooseC(itemStr.get(3).toString());
			chooseItem.setChooseD(itemStr.get(4).toString());
			chooseItem.setAnswer(itemStr.get(5).toString());
			chooseItem.setId(UUID.randomUUID().toString());
			chooseItems.add(chooseItem);
		}
		System.out.println(chooseItems);

	}

	public static void main(String[] args) {
		init();
	}

}
